//
//  BaseNavController.m
//  weibo-01
//
//  Created by HZApple on 16/5/9.
//  Copyright © 2016年 hdu. All rights reserved.
//

#import "BaseNavController.h"
#import "ThemeManager.h"


@interface BaseNavController ()

@end

@implementation BaseNavController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationBar.translucent = NO;
    
    [self loadImage];
    // Do any additional setup after loading the view.
}
//storyboard加载
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
       [self _observeThemeChangeNotification];
    }
    return self;
}
//xib，代码
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        [self _observeThemeChangeNotification];
    }
    return self;
    
}
- (void)_observeThemeChangeNotification {
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChangeAction:) name:kThemeChangeNotification object:nil];
   
}

- (void)themeChangeAction:(NSNotification *) notifation {
    [self loadImage];
}

- (void)loadImage {
    
    ThemeManager *manager = [ThemeManager sharedManager];
    UIImage *image = [manager themeImageWithImageName:@"mask_titlebar64"];
    [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    
    UIColor *titleColor = [[ThemeManager sharedManager] themeColorWithColorName:@"Mask_Title_color"];
    NSDictionary *titleAttributes = @{
                                      NSForegroundColorAttributeName : titleColor
                                      };
    self.navigationBar.titleTextAttributes = titleAttributes;
    
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kThemeChangeNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
